/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#ifndef __LIB3D_MATERIAL_TEXTUREFRAME_H__
#define __LIB3D_MATERIAL_TEXTUREFRAME_H__

#include <memory>
#include <Atom.h>

namespace liba { namespace filesystem { class String; }}

namespace liba {
namespace lib3d {

namespace hard
{
	class Hardware;
	class RenderTexture;
	class Texture;
}

namespace material
{

class TextureSimple;
class TextureAtlas;
struct AtlasFrame;

class TextureFrame
{
public:
	TextureFrame(const filesystem::String &simpleTextureFileName, bool wrap = false);
	TextureFrame(const filesystem::String &atlasTextureFileName, const Atom &frameName);
	TextureFrame(const filesystem::String &atlasTextureFileName, int frameIndex);
	TextureFrame(hard::Hardware * hardware, hard::Texture * texture);
	TextureFrame(const TextureFrame& rhs);
	~TextureFrame();

	bool IsReady();

	int GetWidth();
	int GetHeight();

	float TransformU(float u);
	float TransformV(float v);

	void SetAtlasFrameName(const Atom &frameName);
	void SetAtlasFrameIndex(int frameIndex);

	void render_to_list(hard::Hardware * hardware, hard::RenderTexture * render_texture);

private:
	bool IsSimpleTextureLoaded();
	AtlasFrame *GetAtlasFrame();

private:
	std::auto_ptr <TextureSimple> simpleTexture;
	
	std::auto_ptr <TextureAtlas> atlasTexture;
	AtlasFrame *atlasFrame;

	Atom atlasFrameName;
	int frameIndex;
};


} // namespace material
} // namespace lib3d
} // namespace liba
using namespace liba;

#endif //__LIB3D_MATERIAL_TEXTUREFRAME_H__